package it4s.service.api.twitter.core;



import it4s.service.api.factory.IServiceInstance;
import it4s.service.api.factory.TwitterFactoryInstance;
import it4s.service.api.factory.TwitterInstance;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;



public class OperationTwitter {
	
	
private Twitter twitter;


	
	private static final Logger logger = LoggerFactory
			.getLogger(OperationTwitter.class);
	
	
	public OperationTwitter() {
		IServiceInstance instance=null;
		TwitterInstance instanceTitter=(TwitterInstance)new TwitterFactoryInstance().createServiceInstance(instance);
		if (instanceTitter!=null) {
			twitter=instanceTitter.getTwitter();
		}
		
				
	}
	
	public String getNameTwitterUser(){
		
		String nameUser=null;
		try {
			nameUser=twitter.getScreenName();
		} catch (IllegalStateException e) {
			logger.error(e.getMessage());
		} catch (TwitterException e) {
			logger.error(e.getMessage());
		}
		
		return nameUser;
	}
	
	public void post(String latestStatus){
		
	    try {
			Status status = twitter.updateStatus(latestStatus);
			logger.info("Successfully updated the status to [" + status.getText() + "].");
		} catch (TwitterException e) {
			logger.error(e.getMessage());
		}
		
	}
	
	public void post2(String latestStatus){
		
	    try {
			Status status = twitter.updateStatus(latestStatus);
			logger.info("Successfully updated the status to [" + status.getText() + "].");
		} catch (TwitterException e) {
			logger.error(e.getMessage());
		}
		
	}

}
